<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  let p = new Promise((resolve, reject) => {
    if (Math.random() > 0.5) {
      resolve('成功')
    } else {
      reject('失败')
    }
  })

  p.then(res => {
    console.log(res)
  })
    .catch(err => {
      console.log(err)
    })

  // async 用于修饰函数 被它修饰的函数 返回的一定是promise对象
  async function fn() {
    return 1
  }
  console.log(fn())
  // 返回了个promise对象 
  fn().then(res => {
    console.log(res) //1
  })

  async function fn2() {
    // promise.reject 直接返回失败的状态
    // promise.resolve 直接返回成功的状态
    return Promise.reject(3)
  }
  fn2().catch(err => {
    console.log(err)
  })
</script>

</html>